﻿using System.Windows;
using System.Windows.Controls;

namespace TallyMarks
{
    public partial class MarksUserControl : UserControl
    {
        private double _percentageOfActualSize;

        public MarksUserControl()
        {
            InitializeComponent();
        }

        // Have to resize manually to get layout resizing, not just
        // transform resizing.  Layout resizing will make the controls
        // act appropriately in the wrap-panel as they resize
        public double PercentageOfActualSize
        {
            get
            {
                return _percentageOfActualSize;
            }
            set
            {
                _percentageOfActualSize = value;
                Resize(LayoutRoot);
                Resize(TallyOne);
                Resize(TallyTwo);
                Resize(TallyThree);
                Resize(TallyFour);
                Resize(TallyFive);            
            }
        }

        private void Resize(FrameworkElement element)
        {
            element.Height = element.Height * _percentageOfActualSize;
            element.Width = element.Width * _percentageOfActualSize;

            if (element.Parent != LayoutRoot) return;
            Canvas.SetLeft(element, Canvas.GetLeft(element) * _percentageOfActualSize);
            Canvas.SetTop(element, Canvas.GetTop(element) * _percentageOfActualSize);
        }
    }
}